package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysField;
import com.ruoyi.system.service.ISysFieldService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 字段Controller
 * 
 * @author ruoyi
 * @date 2023-03-13
 */
@RestController
@RequestMapping("/system/field")
public class SysFieldController extends BaseController
{
    @Autowired
    private ISysFieldService sysFieldService;

    /**
     * 查询字段列表
     */
    @PreAuthorize("@ss.hasPermi('system:field:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysField sysField)
    {
        startPage();
        List<SysField> list = sysFieldService.selectSysFieldList(sysField);
        return getDataTable(list);
    }

    /**
     * 导出字段列表
     */
    @PreAuthorize("@ss.hasPermi('system:field:export')")
    @Log(title = "字段", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysField sysField)
    {
        List<SysField> list = sysFieldService.selectSysFieldList(sysField);
        ExcelUtil<SysField> util = new ExcelUtil<SysField>(SysField.class);
        return util.exportExcel(list, "field");
    }

    /**
     * 获取字段详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:field:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysFieldService.selectSysFieldById(id));
    }

    /**
     * 新增字段
     */
    @PreAuthorize("@ss.hasPermi('system:field:add')")
    @Log(title = "字段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysField sysField)
    {
        return toAjax(sysFieldService.insertSysField(sysField));
    }

    /**
     * 修改字段
     */
    @PreAuthorize("@ss.hasPermi('system:field:edit')")
    @Log(title = "字段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysField sysField)
    {
        return toAjax(sysFieldService.updateSysField(sysField));
    }

    /**
     * 删除字段
     */
    @PreAuthorize("@ss.hasPermi('system:field:remove')")
    @Log(title = "字段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysFieldService.deleteSysFieldByIds(ids));
    }
}
